package com.im;

import com.im.handler.WebSocketInitHandler;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class HelloNettyServer {


  public static void main(String[] args) throws InterruptedException {
    EventLoopGroup accept = new NioEventLoopGroup();
    EventLoopGroup deal = new NioEventLoopGroup();
    ServerBootstrap serverBootstrap = new ServerBootstrap();
    try {
      serverBootstrap.group(accept, deal).channel(NioServerSocketChannel.class)
          .childHandler(new WebSocketInitHandler());
      ChannelFuture future = serverBootstrap.bind(8080).sync();
      future.channel().closeFuture().sync();
    } catch (
        Exception e) {
      e.printStackTrace();
    } finally {
      //使用一种优雅的方式进行关闭
      accept.shutdownGracefully();
      deal.shutdownGracefully();
    }
  }


}
